
/*
 * @Autor: Mr Lu
 * @Version: 1.0
 * @Date: 2019-12-03
 * @LastEditors: OBKoro1
 * @LastEditTime: 2019-12-03
 * @Description:  预警信息
 * 组件说明：树形组件
  itemActive:是否需要高亮显示  Boolean
  data:树形组件的数据 Array类型
  props:组件属性  Object {id:'',children:'',name:''}
  lazy:是否开启懒加载 Boolean 
  @load:懒加载回调方法 Funciton  返回当前点击项的所有数据
  @click:点击事件方法 Funciton 返回当前点击项的所有数据
  clickableConditions: 可以点击的条件 Object
    {
        //所有的列表是否可以点击
        all: {
          enable: true
        },

      //部分的列表可以点击 
      //以下条件说明【 orgType = 1或orgType = 2时可以点击】
      part: {
        prop: "orgType", 
        value: [1,2]
      }
    },
 */
<template>
  <div id="Area">
    <div style="height:100%;overflow:auto">
      <mTree
        v-show="tree.data.length"
        :data="tree.data"
        :props="tree.defaultProps"
        :clickableConditions="tree.clickableConditions"
        @click="skipPage"
      ></mTree>
      <NoData v-if="!tree.data.length&&!tree.loading" />
    </div>

    <!-- <mu-dialog
      width="85%"
      max-width="85%"
      dialog-class="dialog-confirm"
      :esc-press-close="false"
      :overlay-close="false"
      :open.sync="openAlert"
    >
      <div class="body">该区域无任务，是否创建新任务？</div>
      <div slot="actions">
        <mu-button flat @click="closeAlertDialog" class="first">取消</mu-button>
        <mu-button flat color="primary" @click="confirm" class="last">确认</mu-button>
      </div>
    </mu-dialog>-->
  </div>
</template>

<script>
import mTree from "@/tree/mTree";
import { MessageBox } from "mint-ui";
export default {
  name: "Area",
  props: ["currentProject",'params'],
  components: {
    mTree
  },
  data() {
    return {
      openAlert: false,
      currentArea: {
        id: "",
        name: ""
      },
      tree: {
        loading: false,

        defaultProps: {
          id: "id",
          name: "name",
          children: "children"
        },
        clickableConditions: {
          all: {
            //所有的是否可以点击
            enable: true
          },
          part: {
            //部分的可以点击的条件
            prop: "orgType",
            value: [1]
          }
        },
        data: []
      }
    };
  },
  computed: {},
  created() {
    this.initPage();
  },
  mounted() {},
  watch: {
    currentProject: {
      handler(newVal, oldVal) {
        this.initPage();
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    initPage() {
      this.tree.loading = true;
      this.$openLoading();
      let params = {
        orgId: this.currentProject.id
      };
      this.$A.Go("get", "/safety/projectArea/tree", params).then(
        response => {
          this.$closeLoading();
          this.tree.loading = false;
          this.tree.data =
            response.body && response.body.length ? response.body : [];
        },
        err => {
          this.$closeLoading();
          this.tree.loading = false;
          console.log(err);
        }
      );
    },
    closeAlertDialog() {
      this.openAlert = false;
    },
    skipPage(treeRowData) {
      //判断此区域下是否有任务
      this.currentArea = {
        id: treeRowData.id,
        name: treeRowData.name
      };
      this.$openLoading();
      let params = {
        projectId: this.currentProject.id,
        areaId: treeRowData.id,
        startTime:this.params.startTime, 
        endTime:this.params.endTime
      };
      this.$A.Go("get", "/safety/measureTask/dataList", params).then(res => {
        this.$closeLoading();
        if (res.code == 200) {
          if (res.body && res.body.length) {
            if (res.body.length == 1) {
              let params = res.body[0];
              //一个任务==》进行测量 StartMeasure
              this.$router.push({
                name: "StartMeasure",
                query: {
                  id: params.id,
                  areaId: params.areaId,
                  areaName: params.areaName,
                  deptId: params.deptId,
                  deptName: params.deptName,
                  areaName: params.areaName,
                  photoUrl: params.photoUrl,
                  projectId: params.projectId,
                  projectName: params.projectName,
                  pointList: JSON.stringify(params.measurePointVoList)
                }
              });
            } else {
              //如果有多个任务，进入列表页
              this.$router.push({
                name: "TaskModeAreaList",
                query: {
                  projectId: params.projectId,
                  areaId: params.areaId,

                }
              });
            }
          } else {
            //弹出提示
            this.$nextTick(() => {
              MessageBox({
                message: "该区域无点位标记，是否标记？",
                showCancelButton: true,
                showConfirmButton: true,
                confirmButtonText: "确认",
                cancelButtonText: "取消"
              })
                .then((value, action) => {
                  if (value == "confirm") {
                    this.$emit("showAddTask", this.currentArea);
                    this.closeAlertDialog();
                  } else {
                  }
                })
                .catch(err => {});
            });
          }
        }
      });
    }
  },
  destroyed() {}
};
</script>

<style lang="scss">
#Area {
  height: 100%;
  .lan-nodata {
    height: 100%;
    background: #fff;
  }
}
</style>
